<?php
namespace app\seller\controller;
use think\Input;
class Channel extends Common{
    public function initialize(){
        parent::initialize(); 
        $this->assign('shoplist',cache('shoplist'));   
        $this->assign('cionlist',cache('cionlist'));  
    }
    public function index(){
    	if(request()->isPost()){
            $page =input('page')?input('page'):1;
            $pageSize =input('limit')?input('limit'):config('pageSize'); 
            $shopid=input('shopid')?input('shopid'):session('seller.id');
            $list=db('channel')->alias('c')
                ->join(config('database.prefix') . 'users u', 'c.userid = u.id', 'left')
                ->field('c.*,u.username,u.mobile')
                ->where('c.shopid',$shopid)->order('c.open desc,c.id desc') 
                ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
                ->toArray();
            foreach ($list['data'] as $k=>$v){
                $list['data'][$k]['addtime'] = date('Y-m-d H:i',$v['addtime']);
                $list['data'][$k]['numberall']=db('channel_order')->where('channelid',$v['id'])->sum('number').'/个';
                if($v['open']===0){
                	$list['data'][$k]['opentype'] ='<span class="red">审核中</span>';
                }else{
                	$list['data'][$k]['opentype'] ='<span class="gre">正常</span>';
                }
            }
            return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
        } 
        $this->assign('title','通道管理');
        return $this->fetch();
    }  
}